﻿Imports Microsoft.Xna.Framework.Input

Public Class ControllerFactoryEnumerable
    Implements IEnumerable(Of IControllerFactory)

    Private Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of IControllerFactory) Implements System.Collections.Generic.IEnumerable(Of IControllerFactory).GetEnumerator
        Dim l As List(Of IControllerFactory) = New List(Of IControllerFactory)()

        l.Add(New VirtualControllerFactory())

        If GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One).IsConnected Then
            l.Add(New Xbox360ControllerFactory(Microsoft.Xna.Framework.PlayerIndex.One))
        End If

        If GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.Two).IsConnected Then
            l.Add(New Xbox360ControllerFactory(Microsoft.Xna.Framework.PlayerIndex.Two))
        End If

        If GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.Three).IsConnected Then
            l.Add(New Xbox360ControllerFactory(Microsoft.Xna.Framework.PlayerIndex.Three))
        End If

        If GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.Four).IsConnected Then
            l.Add(New Xbox360ControllerFactory(Microsoft.Xna.Framework.PlayerIndex.Four))
        End If

        Return l.GetEnumerator()
    End Function

    Private Function GetEnumeratorObj() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return GetEnumerator()
    End Function
End Class
